package com.rightsidetech.http.controller.storeApp.material;

import com.github.pagehelper.PageInfo;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.rightsidetech.commom.base.ResponseData;
import com.rightsidetech.commom.enums.CodeIdEnum;
import com.rightsidetech.commom.utils.BeanValidator;
import com.rightsidetech.http.aspect.Log;
import com.rightsidetech.http.aspect.Token;
import com.rightsidetech.http.base.BaseController;
import com.rightsidetech.system.dtos.request.BatteryCheckAddReq;
import com.rightsidetech.system.dtos.request.BatteryCheckReq;
import com.rightsidetech.system.entity.SysBatteryCheck;
import com.rightsidetech.system.service.SysBatteryCheckService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.ConstraintViolation;

/**
 * @Package: com.rightsidetech.http.controller.admin.system
 * @ClassName: SysBatteryCheckController
 * @Author: yinj
 * @CreateTime: 2022-1-6 14:48:29
 * @Description: 电池检测相关
 */
@RestController
@RequestMapping("/storeApp/battery_check")
@ShenyuSpringMvcClient(path = "/storeApp/battery_check/**")
@Api(tags = "电池检测相关")
public class StoreBatteryCheckController extends BaseController {

    @Resource
    private SysBatteryCheckService sysBatteryCheckService;


    @Log
    @Token
    @GetMapping("/page")
    @ApiOperation("电池检测列表")
    @ApiOperationSupport(ignoreParameters = {"agentId", "warranty","checkResult","status","timeType","areaId","storeId","startTime","endTime"})
    public ResponseData<PageInfo<SysBatteryCheck>> page(BatteryCheckReq request) throws Exception {
        request.setStoreId(Long.parseLong(getAttribute()));

        return sysBatteryCheckService.page(request);
    }

    @Log
    @Token
    @PostMapping("/add")
    @ApiOperation("添加")
    public ResponseData handle(@RequestBody BatteryCheckAddReq request) throws Exception {

        ConstraintViolation validate = BeanValidator.validate(request);
        if (validate != null) {
            return new ResponseData<>(CodeIdEnum.ParameterMalformed.getValue(), validate.getMessage());
        }

        request.setStoreId(Long.parseLong(getAttribute()));

        return sysBatteryCheckService.add(request);
    }


}
